package edu.nf.vac.admin.controller;

import edu.nf.vac.admin.vo.PageVO;
import edu.nf.vac.admin.vo.ResultVO;
import org.springframework.http.HttpStatus;

import java.util.List;

/**
 * @Author : QYM
 * @create 2022/4/2
 */

public class BaseController {
    public ResultVO success(){
        ResultVO vo = new ResultVO();
        vo.setCode(HttpStatus.OK.value());
        return vo;
    }

    public <T> ResultVO<T> success(T data){
        ResultVO<T> vo = new ResultVO<>();
        vo.setCode(HttpStatus.OK.value());
        vo.setData(data);
        return vo;
    }

    public ResultVO fail(int code,String message){
        ResultVO vo = new ResultVO();
        vo.setCode(code);
        vo.setMessage(message);
        return vo;
    }

    public ResultVO fail(int code){
        ResultVO vo = new ResultVO();
        vo.setCode(code);
        return vo;
    }

    /**
     * 分页结果集
     * @param total
     * @param list
     * @param <T>
     * @return
     */
    public <T> ResultVO<List<T>> pageResult(long total,List<T> list){
        PageVO vo = new PageVO();
        vo.setCode(0);
        vo.setCount(total);
        vo.setData(list);
        return vo;
    }
}
